// log_manager.h
#pragma once

#include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <memory>
#include <string>

class LoggerManager {
public:
    LoggerManager(const std::string& log_dir = "log",
                  const std::string& file_prefix = "app",
                  int retention_days = 5);
    ~LoggerManager() = default;

    std::shared_ptr<spdlog::logger> getLogger() const { return logger_; }
    void cleanupOldLogFiles(int days);
    void setLogLevel(spdlog::level::level_enum level);

private:
    void initializeLogDirectory();
    bool isOlderThanDays(const std::string& timestamp_str,
                        std::chrono::system_clock::time_point days_ago);
    std::string getCurrentTimestamp();

    std::string log_directory_;
    std::string file_prefix_;
    int retention_days_;
    std::shared_ptr<spdlog::logger> logger_;
};
